#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/io.h>
//#include <mach/io.h>
//#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>

#include "common.h"
#include "n3_drv.h"


#define PLL_MODE_144MHz 1 // 36MHz * 4
#define PLL_MODE_108MHz 0 // 27MHz * 4

static unsigned int DEV_ADDR;

void N3_video_chnl_stop(unsigned char ch);
void N3_video_chnl_start(unsigned char ch);
//#define  N3_Each_Setting   //add setting for SD and HD mix setting

/*4ch 720P; 0x01:4ch 720H 37M; 0x02:4ch 720h 27M; 0x03: other setting */
unsigned int N3_Mode =0x03;

static void Write_I2C(unsigned char dev_addr, unsigned char addr, unsigned char *data, unsigned char val, int cnt)
{
    int i;
//  unsigned char buf[512] = {0,};
    if(cnt == 1)
    {
        I2CWriteByte( dev_addr, addr, val );
    }
    else
    {
        for(i=0;i<cnt;i++)
        {
            I2CWriteByte( dev_addr, addr + i, data[i] );
        }
    }
}
#if 1
void video_fsc_check(unsigned char ch)
{
    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+(ch%4));
    I2CWriteByte(DEV_ADDR, 0x2A, 0xD4);
    msleep(40);
    I2CWriteByte(DEV_ADDR, 0x2A, 0xD2);
    printk("new fsc check fun test\n");
}
#else
void video_fsc_check(unsigned char ch)
{
    unsigned char val_0xe8,val_5x26,val_5x25,tmp;
    int i;
    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+(ch%4));
    val_5x25 = I2CReadByte(DEV_ADDR, 0x25);
    tmp = ((val_5x25&0x0F)==0x0A?0x0C:0x0A)|(val_5x25&0xF0);
    val_5x26 = I2CReadByte(DEV_ADDR, 0x26);
    I2CWriteByte(DEV_ADDR, 0x26, 0x88);
    for(i=0;i<10;i++)
    {
        I2CWriteByte(DEV_ADDR, 0xFF, 0);
        val_0xe8=I2CReadByte(DEV_ADDR, 0xE8+(ch%4));
        if((val_0xe8&0x02)==0)
        {
            I2CWriteByte(DEV_ADDR, 0xFF, 0x05+(ch%4));
            I2CWriteByte(DEV_ADDR, 0x25, tmp);
            msleep(40);
            I2CWriteByte(DEV_ADDR, 0x25, val_5x25);
            printk("func[video_fsc_check]ch[%d]cnt[%d]tmp[%x]val_5x25[%x]\n", ch, i, tmp, val_5x25);
            msleep(10);
            continue;
        }
        printk("N3 [video_fsc_check]ch[%d] ok\n", ch);
        break;
    }
    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+(ch%4));
    I2CWriteByte(DEV_ADDR, 0x26, val_5x26);
}
#endif

static BYTE N3_B0_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0x20,0x03,0x00,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xa0,0xff,0xff,0xff,0xff,
/*1*/ 0x92,0x92,0x92,0x92,0x80,0x80,0x80,0x80,0x18,0x18,0x18,0x18,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,
/*3*/ 0x11,0x11,0x11,0x11,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x88,0x88,0x88,0x88,
/*4*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x00,0x00,0x00,0x00,0xf1,0x10,0x32,0x00,0xc0,0xc0,0xc0,0xc0,0x1e,0x1e,0x1e,0x1e,
/*6*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0x00,0x00,0x77,0x07,0x07,
/*9*/ 0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,
/*A*/ 0x15,0x15,0x15,0x15,0x07,0x07,0x07,0x07,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x0f,0x0f,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x01,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x1d,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x18,0x40,0x40,0x40,0x2a,0x23,0x23,0x23,0x01,0x0f,0x0b,0x55,
/*F*/ 0x00,0xcb,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

static BYTE N3_B1_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
/*9*/ 0x01,0x01,0x01,0x01,0x50,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x00,0x00,0x10,0x10,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

static BYTE N3_B5678_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0e,0x0c,0x1f,0x00,0x20,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x04,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x01,0x88,
/*2*/ 0x88,0x20,0x23,0x00,0x2a,0xda,0xf0,0x57,0x90,0x1f,0x52,0x78,0x0c,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*6*/ 0x53,0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x3f,0xff,0xff,0xff,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5c,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0x20,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0xb9,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x00,0x13,0x00,0x00,0x01,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0xec,0x40,0x00,0x00,0x00,0x0f,0x99,0x0f,0x83,0x40,0x40,0x01,0x10,
/*F*/ 0x00,0xff,0xb4,0x06,0x11,0x01,0x82,0x6b,0x0d,0x78,0x0a,0x35,0x03,0x00,0x00,0x05
};


static BYTE N3_B9_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x04,0x06,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x28,0x30,0x38,0x40,0x48,0x50,
/*1*/ 0x58,0x60,0x68,0x70,0x78,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*2*/ 0x01,0x03,0x05,0x07,0x0b,0x0f,0x13,0x17,0x1b,0x1f,0x27,0x2f,0x37,0x3f,0x47,0x4f,
/*3*/ 0x57,0x5f,0x67,0x6f,0x77,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*4*/ 0x60,0x60,0x60,0x60,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x2a,0x23,0x23,0x23,
/*5*/ 0x4d,0x0e,0x88,0x6c,0x4d,0x0e,0x88,0x6c,0x4d,0x0e,0x88,0x6c,0x4d,0x0e,0x88,0x6c,
/*6*/ 0x00,0x00,0x00,0x00,0x18,0xc2,0x01,0x1e,0x02,0x64,0x60,0x3c,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*F*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
};

static BYTE N3_B0_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0x20,0x03,0x00,0x00,0x00,0x00,0xdd,0xdd,0xdd,0xdd,0x00,0x00,0x00,0x00,
/*1*/ 0x90,0x90,0x90,0x90,0x80,0x80,0x80,0x80,0x18,0x18,0x18,0x18,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x88,0x88,0x88,0x88,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,
/*5*/ 0x04,0x04,0x04,0x04,0x01,0x10,0x32,0x00,0x60,0x60,0x60,0x60,0x1e,0x1e,0x1e,0x1e,
/*6*/ 0x00,0x00,0x00,0x00,0x0d,0x0d,0x0d,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x10,0x10,0x10,0x10,0x77,0x08,0x08,
/*9*/ 0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,
/*A*/ 0x15,0x15,0x15,0x15,0x05,0x05,0x05,0x05,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x0f,0x0f,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x02,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x1e,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x17,0x40,0x40,0x40,0x2a,0x23,0x23,0x23,0x01,0x0f,0x0d,0x55,
/*F*/ 0x00,0x74,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

static BYTE N3_B1_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
/*9*/ 0x01,0x01,0x01,0x01,0x50,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x00,0x00,0x10,0x10,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

static BYTE N3_B5678_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0e,0x0c,0x1f,0x00,0x20,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x13,
/*1*/ 0x06,0x04,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*2*/ 0x88,0x20,0x23,0x00,0x2a,0xca,0xf0,0x57,0x90,0x1f,0x52,0x78,0x08,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*6*/ 0x53,0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x3f,0xff,0xff,0xff,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0x20,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0xb9,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x0d,0x13,0x00,0x00,0x01,0x20,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0xf4,0x40,0x00,0x00,0x00,0x0f,0xb5,0x0f,0x6e,0x40,0x40,0x01,0x40,
/*F*/ 0x10,0xff,0xc0,0x06,0x41,0x01,0x82,0x6b,0x0d,0x78,0x0a,0x5e,0x03,0x00,0x00,0x05
};

static BYTE N3_B9_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x04,0x06,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x28,0x30,0x38,0x40,0x48,0x50,
/*1*/ 0x58,0x60,0x68,0x70,0x78,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*2*/ 0x01,0x03,0x05,0x07,0x0b,0x0f,0x13,0x17,0x1b,0x1f,0x27,0x2f,0x37,0x3f,0x47,0x4f,
/*3*/ 0x57,0x5f,0x67,0x6f,0x77,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*4*/ 0x60,0x60,0x60,0x60,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x2a,0x53,0x53,0x53,
/*5*/ 0x75,0x35,0xb4,0x6c,0x75,0x35,0xb4,0x6c,0x75,0x35,0xb4,0x6c,0x75,0x35,0xb4,0x6c,
/*6*/ 0x00,0x00,0x00,0x00,0x18,0xc2,0x01,0x1e,0x02,0x64,0x60,0x3c,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*F*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
};

static void WriteBankAll_N3_H960( int _0ntsc1pal )
{
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK0,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B0_PAL_Buf : N3_B0_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B1_PAL_Buf : N3_B1_NTSC_Buf,0, 255 );

    //Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    //Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B2_PAL_Buf : N3_B2_NTSC_Buf,0, 255 );

    /*
    --------------------[BANK = 2]----------------------
    0x00=0x13
    0x02=0x13
    0x04=0x13
    0x06=0x13
     */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    Write_I2C( DEV_ADDR, 0x00, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x02, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x04, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x06, NULL, 0x13,1);

    /*
    --------------------[BANK = 3]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK3,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);

    /*
    --------------------[BANK = 4]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK4,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);


    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK5,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_PAL_Buf : N3_B5678_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK6,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_PAL_Buf : N3_B5678_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK7,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_PAL_Buf : N3_B5678_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK8,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_PAL_Buf : N3_B5678_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK9,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B9_PAL_Buf : N3_B9_NTSC_Buf,0, 255 );
}

static void system_init_N3_H960(void)
{
    I2CWriteByte(DEV_ADDR,0xFF,0x01);
    I2CWriteByte(DEV_ADDR,0x82,0x14);
    I2CWriteByte(DEV_ADDR,0x83,0x2C);
    I2CWriteByte(DEV_ADDR,0x3e,0x10);
    I2CWriteByte(DEV_ADDR,0x80,0x60);
    I2CWriteByte(DEV_ADDR,0x80,0x61);
    msleep(100);
    I2CWriteByte(DEV_ADDR,0x80,0x40);
    I2CWriteByte(DEV_ADDR,0x81,0x02);
    I2CWriteByte(DEV_ADDR,0x97,0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR,0x80,0x60);
    I2CWriteByte(DEV_ADDR,0x81,0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR,0x97,0x0F);
    I2CWriteByte(DEV_ADDR,0x38,0x18);
    I2CWriteByte(DEV_ADDR,0x38,0x08);
    msleep(100);
}

//change: 0x58... 0x98... 0x93...
static BYTE N3_B0_720H_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xa0,0xff,0xff,0xff,0xff,
/*1*/ 0x92,0x92,0x92,0x92,0x80,0x80,0x80,0x80,0x18,0x18,0x18,0x18,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,0x2f,0x82,0x0b,0x43,
/*3*/ 0x11,0x11,0x11,0x11,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x88,0x88,0x88,0x88,
/*4*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x00,0x00,0x00,0x00,0xf1,0x10,0x32,0x00,0x89,0x89,0x89,0x89,0x1e,0x1e,0x1e,0x1e,
/*6*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x77,0x00,0x00,
/*9*/ 0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x09,0x09,0x09,0x09,0x00,0x00,0x00,0x00,
/*A*/ 0x15,0x15,0x15,0x15,0x07,0x07,0x07,0x07,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x0f,0x0f,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x01,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x1d,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x18,0x40,0x40,0x40,0x2a,0x23,0x23,0x23,0x01,0x0f,0x0b,0x55,
/*F*/ 0x00,0xcb,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


static BYTE N3_B1_720H_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x82,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
/*9*/ 0x01,0x01,0x01,0x01,0x50,0x00,0x00,0x0f,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x00,0x00,0x10,0x10,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};


static BYTE N3_B5678_720H_NTSC_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0c,0x0c,0x1f,0x00,0x20,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x04,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x01,0x88,
/*2*/ 0x88,0x20,0x23,0x00,0x2a,0xda,0xf0,0x57,0x90,0x1f,0x52,0xA8,0x0c,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*6*/ 0x53,0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x3f,0xff,0xff,0xff,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5c,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0x20,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0xb9,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x00,0x13,0x00,0x00,0x01,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0xec,0x40,0x00,0x00,0x00,0x0f,0x99,0x0f,0x83,0x40,0x40,0x01,0x10,
/*F*/ 0x00,0xff,0xb4,0x06,0x11,0x01,0x82,0x6b,0x0d,0x78,0x0a,0x35,0x03,0x00,0x00,0x05
};


static BYTE N3_B0_720H_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x00,0xdd,0xdd,0xdd,0xdd,0x00,0x00,0x00,0x00,
/*1*/ 0x90,0x90,0x90,0x90,0x80,0x80,0x80,0x80,0x18,0x18,0x18,0x18,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,0x2f,0x02,0x0b,0x43,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x88,0x88,0x88,0x88,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,
/*5*/ 0x04,0x04,0x04,0x04,0x01,0x10,0x32,0x00,0x70,0x70,0x70,0x70,0x1e,0x1e,0x1e,0x1e,
/*6*/ 0x00,0x00,0x00,0x00,0x0d,0x0d,0x0d,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x77,0x00,0x00,
/*9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,
/*A*/ 0x15,0x15,0x15,0x15,0x05,0x05,0x05,0x05,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x0f,0x0f,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x02,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x1e,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x17,0x40,0x40,0x40,0x2a,0x23,0x23,0x23,0x01,0x0f,0x0d,0x55,
/*F*/ 0x00,0x74,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

static BYTE N3_B1_720H_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x82,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
/*9*/ 0x01,0x01,0x01,0x01,0x50,0x00,0x00,0x0f,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x00,0x00,0x10,0x10,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

//change: 0x01, 0x2B
static BYTE N3_B5678_720H_PAL_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0c,0x0c,0x1f,0x00,0x20,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x13,
/*1*/ 0x06,0x04,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*2*/ 0x88,0x20,0x23,0x00,0x2a,0xca,0xf0,0x57,0x90,0x1f,0x52,0xA8,0x08,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*6*/ 0x53,0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x3f,0xff,0xff,0xff,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0x20,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0xb9,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x0d,0x13,0x00,0x00,0x01,0x20,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0xf4,0x40,0x00,0x00,0x00,0x0f,0xb5,0x0f,0x6e,0x40,0x40,0x01,0x40,
/*F*/ 0x10,0xff,0xc0,0x06,0x41,0x01,0x82,0x6b,0x0d,0x78,0x0a,0x5e,0x03,0x00,0x00,0x05
};

static void WriteBankAll_N3_H720( int _0ntsc1pal )
{
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK0,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B0_720H_PAL_Buf : N3_B0_720H_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B1_720H_PAL_Buf : N3_B1_720H_NTSC_Buf,0, 255 );

    //Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    //Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B2_PAL_Buf : N3_B2_NTSC_Buf,0, 255 );

    /*
    --------------------[BANK = 2]----------------------
    0x00=0x13
    0x02=0x13
    0x04=0x13
    0x06=0x13
     */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    Write_I2C( DEV_ADDR, 0x00, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x02, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x04, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x06, NULL, 0x13,1);

    /*
    --------------------[BANK = 3]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK3,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);

    /*
    --------------------[BANK = 4]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK4,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);


    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK5,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720H_PAL_Buf : N3_B5678_720H_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK6,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720H_PAL_Buf : N3_B5678_720H_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK7,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720H_PAL_Buf : N3_B5678_720H_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK8,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720H_PAL_Buf : N3_B5678_720H_NTSC_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK9,1);
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B9_PAL_Buf : N3_B9_NTSC_Buf,0, 255 );
}

static void system_init_N3_H720(unsigned char PLL_MODE)
{
    I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
    if(PLL_MODE == PLL_MODE_144MHz)
    {
        I2CWriteByte(DEV_ADDR, 0x82, 0x14); // 144M ?
        I2CWriteByte(DEV_ADDR, 0x83, 0x2C);
    }
    else
    {
        I2CWriteByte(DEV_ADDR, 0x82, 0x22); //108M
        I2CWriteByte(DEV_ADDR, 0x83, 0x20);
    }
    I2CWriteByte(DEV_ADDR, 0x3e, 0x10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x80, 0x61);
    msleep(40); //100
    I2CWriteByte(DEV_ADDR, 0x80, 0x40);
    I2CWriteByte(DEV_ADDR, 0x81, 0x02);
    I2CWriteByte(DEV_ADDR, 0x97, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x81, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x97, 0x0F);
    I2CWriteByte(DEV_ADDR, 0x38, 0x18);
    I2CWriteByte(DEV_ADDR, 0x38, 0x08);
    msleep(40); //100
}

//change 0x18
static BYTE N3_B0_720p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x08,0x08,0x08,0x08,
/*1*/ 0x88,0x88,0x88,0x88,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x90,0x90,0x90,0x90,
/*4*/ 0xfd,0xfd,0xfd,0xfd,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x04,0x04,0x04,0x04,
/*5*/ 0x04,0x04,0x04,0x04,0xf1,0x10,0x32,0x00,0x90,0x90,0x90,0x90,0x9e,0x9e,0x9e,0x9e,
/*6*/ 0x00,0x00,0x00,0x00,0xb2,0xb2,0xb2,0xb2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x77,0x0d,0x0d,
/*9*/ 0x0d,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,
/*A*/ 0x05,0x05,0x05,0x05,0x01,0x01,0x01,0x01,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x01,0x0f,0x0f,0xff,0x00,0x03,0x0f,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x04,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x08,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x1b,0x40,0x40,0x40,0x42,0x47,0x47,0x47,0x01,0x0f,0x0f,0x55,
/*F*/ 0xbf,0xcd,0x00,0x0e,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x00
};


static BYTE N3_B1_720p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x82,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,
/*9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x01,0x01,0x01,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0x00,0xd0,0xdd,0x0d,
/*C*/ 0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0xFF,0x00,0x43,0x43,0x43,0x43,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

static BYTE N3_B5678_720p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0e,0x0c,0x1f,0x00,0x24,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x01,0x88,
/*2*/ 0x84,0x20,0x23,0x00,0x2a,0xdc,0xf0,0x57,0x90,0x70,0x72,0xA8,0x00,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
/*6*/ 0x53,0x53,0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x01,0x81,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5c,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0xa0,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x16,0x13,0x00,0x00,0x01,0x04,0x00,0x55,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x0e,0x12,0x14,0x1c,0x2c,0x34,0x00,
/*E*/ 0x00,0x00,0x00,0x44,0x00,0x00,0x00,0x00,0x01,0xbb,0x01,0xbb,0x40,0x40,0x02,0xf5,
/*F*/ 0x20,0xff,0xb0,0x04,0xf6,0x02,0x7e,0x68,0x0d,0x75,0x0a,0x26,0x03,0x00,0x00,0x05
};

static BYTE N3_B0_720p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x08,0x08,0x08,0x08,
/*1*/ 0x88,0x88,0x88,0x88,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x90,0x90,0x90,0x90,
/*4*/ 0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x04,0x04,0x04,0x04,
/*5*/ 0x04,0x04,0x04,0x04,0x01,0x10,0x10,0x00,0x88,0x88,0x88,0x88,0x9e,0x9e,0x9e,0x9e,
/*6*/ 0x00,0x00,0x00,0x00,0xb1,0xb1,0xb1,0xb1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x77,0x0d,0x0d,
/*9*/ 0x0d,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,
/*A*/ 0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x01,0x01,0xff,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x08,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x09,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0x00,0x00,0x19,0x40,0x40,0x40,0x42,0x47,0x47,0x47,0x01,0x0f,0x01,0x55,
/*F*/ 0x03,0x29,0x00,0x0e,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x77,0x00
};

static BYTE N3_B1_720p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x82,0x0f,0x0f,0x0f,0x0f,0x0f,0x1a,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x08,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,
/*9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x01,0x01,0x01,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0x00,0xd0,0xdd,0x0d,
/*C*/ 0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0xFF,0x00,0x43,0x43,0x43,0x43,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

//change 0x2B /0x58
static BYTE N3_B5678_720p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0d,0x0c,0x1f,0x00,0x24,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*2*/ 0x84,0x20,0x23,0x00,0x2a,0xdc,0xf0,0x57,0x90,0x70,0x72,0xA8,0x00,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
/*6*/ 0x53,0x53,0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0xa0,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x16,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x0e,0x12,0x14,0x1c,0x2c,0x34,0x00,
/*E*/ 0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*F*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05
};

static void WriteBankAll_N3_720P( int _0_30P_1_25P )
{
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK0,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B0_720p_25fps_Buf : N3_B0_720p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B1_720p_25fps_Buf : N3_B1_720p_30fps_Buf,0, 255 );

    /*
    --------------------[BANK = 2]----------------------
    0x00=0x13
    0x02=0x13
    0x04=0x13
    0x06=0x13
     */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    Write_I2C( DEV_ADDR, 0x00, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x02, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x04, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x06, NULL, 0x13,1);

    /*
    --------------------[BANK = 3]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK3,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);

    /*
    --------------------[BANK = 4]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK4,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);


    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK5,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_720p_25fps_Buf : N3_B5678_720p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK6,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_720p_25fps_Buf : N3_B5678_720p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK7,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_720p_25fps_Buf : N3_B5678_720p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK8,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_720p_25fps_Buf : N3_B5678_720p_30fps_Buf,0, 255 );

    /*
    --------------------[BANK = 9]----------------------
    0x40=0x00
    0x41=0x00
    0x42=0x00
    0x43=0x00
    0x44=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK9,1);
    Write_I2C( DEV_ADDR, 0x40, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x41, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x42, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x43, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x44, NULL, 0x00,1);
}

static void system_init_N3_720P(void)
{
    I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
    I2CWriteByte(DEV_ADDR, 0x82, 0x14);
    I2CWriteByte(DEV_ADDR, 0x83, 0x2C);
    I2CWriteByte(DEV_ADDR, 0x3e, 0x10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x80, 0x61);
    msleep(40); //100
    I2CWriteByte(DEV_ADDR, 0x80, 0x40);
    I2CWriteByte(DEV_ADDR, 0x81, 0x02);
    I2CWriteByte(DEV_ADDR, 0x97, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x81, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x97, 0x0F);
    I2CWriteByte(DEV_ADDR, 0x38, 0x18);
    I2CWriteByte(DEV_ADDR, 0x38, 0x08);
    msleep(40); //100
}


static BYTE N3_B0_1080p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0x20,0x03,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0xf4,0xf4,0xf4,0xf4,
/*1*/ 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x92,0x0b,0x71,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0xa0,0xa0,0xa0,0xa0,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x00,0x00,0x00,0x00,0xf1,0x10,0x10,0x00,0x56,0x56,0x56,0x56,0xbe,0x9e,0x9e,0x9e,
/*6*/ 0x00,0x00,0x00,0x00,0x8d,0x8d,0x8d,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x77,0x09,0x09,
/*9*/ 0x09,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,
/*A*/ 0x07,0x07,0x07,0x07,0x01,0x01,0x01,0x01,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x01,0x01,0xff,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x40,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x08,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0xff,0x00,0x00,0x00,0x17,0x40,0x40,0x40,0x52,0x57,0x57,0x57,0x01,0x0f,0x01,0x55,
/*F*/ 0x00,0x5c,0x00,0x0e,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x22,0x00
};


static BYTE N3_B1_1080p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x84,0x84,0x84,0x84,
/*9*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x69,0x69,0x69,0x69,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

static BYTE N3_B5678_1080p_30fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xd0,0x0c,0x0c,0x1f,0x00,0x24,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x01,0x88,
/*2*/ 0x84,0x20,0x23,0x00,0x1a,0xda,0xf0,0x57,0x90,0x70,0x52,0xa8,0x00,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xc6,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x30,
/*6*/ 0x53,0x53,0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x01,0x81,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5c,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0xa0,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0x39,0xb2,0x05,0x04,0xa0,0x00,0x00,0x00,
/*C*/ 0x16,0x13,0x00,0x00,0x0f,0xa0,0x02,0x77,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1f,0x2b,0x7f,0xff,0xff,0xff,0x00,
/*E*/ 0x00,0x00,0x00,0x43,0x00,0x00,0x00,0x00,0x01,0xea,0x01,0xec,0x40,0x40,0x04,0x4c,
/*F*/ 0x30,0xff,0x20,0x03,0x6d,0x04,0x97,0x7f,0x0d,0x8c,0x0b,0x47,0x03,0x00,0x00,0x05
};

static BYTE N3_B0_1080p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x00,0x00,0x20,0x03,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0xf4,0xf4,0xf4,0xf4,
/*1*/ 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0xaf,0xaf,0xaf,0xaf,
/*2*/ 0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,0x2f,0x92,0x0b,0x41,
/*3*/ 0x12,0x12,0x12,0x12,0x04,0x04,0x04,0x04,0x0a,0x0a,0x0a,0x0a,0x80,0x80,0x80,0x80,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x00,0x00,0x00,0x00,0x01,0x10,0x10,0x00,0x78,0x78,0x78,0x78,0xbe,0xbe,0xbe,0xbe,
/*6*/ 0x00,0x00,0x00,0x00,0x8f,0x8f,0x8f,0x8f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0xff,0xff,0xff,0xff,
/*8*/ 0x0f,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x77,0x0a,0x0a,
/*9*/ 0x0a,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,
/*A*/ 0x07,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x01,0x01,0xff,0x00,0x01,0x00,
/*C*/ 0x0f,0x00,0x01,0x01,0xff,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*D*/ 0x80,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x08,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*E*/ 0x00,0x00,0xff,0x00,0x17,0x40,0x40,0x40,0x52,0x57,0x57,0x57,0x01,0x0f,0x01,0x55,
/*F*/ 0x00,0x22,0x00,0x0e,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x33,0x00
};

static BYTE N3_B1_1080p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x19,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*1*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*2*/ 0x88,0x88,0x03,0x10,0x14,0x15,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*3*/ 0xaa,0x82,0x00,0x00,0x00,0x8c,0xa0,0x00,0x09,0x01,0x80,0x30,0x00,0x00,0x10,0x00,
/*4*/ 0x0f,0x0f,0x0f,0x0f,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0x60,0x00,0x14,0x2c,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x84,0x84,0x84,0x84,
/*9*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*A*/ 0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*B*/ 0x00,0x00,0x00,0x00,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,0xf7,0xf7,0x00,0x00,
/*C*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,0x00,0x69,0x69,0x69,0x69,
/*D*/ 0x00,0x00,0x00,0xf0,0x00,0x01,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*E*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*F*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01
};

static BYTE N3_B5678_1080p_25fps_Buf[] = {
   // 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
/*0*/ 0xc0,0x0c,0x0c,0x1f,0x00,0x24,0x40,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*1*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*2*/ 0x84,0x20,0x23,0x00,0x2a,0xdc,0xf0,0x57,0x90,0x70,0x52,0xa8,0x00,0x68,0x00,0x07,
/*3*/ 0x00,0x01,0x64,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*5*/ 0x84,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x30,
/*6*/ 0x53,0x53,0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*7*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x01,0x81,0x01,0x01,0x00,0x00,0x11,0x80,0x00,0x00,
/*8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*9*/ 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*A*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0xa0,
/*B*/ 0x40,0x50,0x0e,0x00,0x00,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xa0,0x00,0x00,0x00,
/*C*/ 0x16,0x13,0x00,0x00,0x01,0x20,0x00,0x33,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*D*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1f,0x2b,0x7f,0xff,0xff,0xff,0x00,
/*E*/ 0x00,0x00,0x00,0x44,0x00,0x00,0x00,0x00,0x01,0xee,0x01,0xee,0x40,0x40,0x04,0x4c,
/*F*/ 0x31,0xff,0xc0,0x03,0x6d,0x04,0x97,0x7e,0x0e,0x8c,0x0b,0x73,0x03,0x00,0x00,0x05
};

static void WriteBankAll_N3_1080P( int _0_30P_1_25P )
{

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK0,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B0_1080p_25fps_Buf : N3_B0_1080p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B1_1080p_25fps_Buf : N3_B1_1080p_30fps_Buf,0, 255 );

    /*
    --------------------[BANK = 2]----------------------
    0x00=0x13
    0x02=0x13
    0x04=0x13
    0x06=0x13
     */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);
    Write_I2C( DEV_ADDR, 0x00, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x02, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x04, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x06, NULL, 0x13,1);

    /*
    --------------------[BANK = 3]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK3,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);

    /*
    --------------------[BANK = 4]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK4,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);


    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK5,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_1080p_25fps_Buf : N3_B5678_1080p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK6,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_1080p_25fps_Buf : N3_B5678_1080p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK7,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_1080p_25fps_Buf : N3_B5678_1080p_30fps_Buf,0, 255 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK8,1);
    Write_I2C( DEV_ADDR, 0x00, _0_30P_1_25P? N3_B5678_1080p_25fps_Buf : N3_B5678_1080p_30fps_Buf,0, 255 );

    /*
    --------------------[BANK = 9]----------------------
    0x40=0x00
    0x41=0x00
    0x42=0x00
    0x43=0x00
    0x44=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK9,1);
    Write_I2C( DEV_ADDR, 0x40, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x41, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x42, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x43, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x44, NULL, 0x00,1);
}

static void system_init_N3_1080P(void)
{
    I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
    I2CWriteByte(DEV_ADDR, 0x82, 0x14);
    I2CWriteByte(DEV_ADDR, 0x83, 0x2C);
    I2CWriteByte(DEV_ADDR, 0x3e, 0x10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x80, 0x61);
    msleep(100);
    I2CWriteByte(DEV_ADDR, 0x80, 0x40);
    I2CWriteByte(DEV_ADDR, 0x81, 0x02);
    I2CWriteByte(DEV_ADDR, 0x97, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x80, 0x60);
    I2CWriteByte(DEV_ADDR, 0x81, 0x00);
    msleep(10);
    I2CWriteByte(DEV_ADDR, 0x97, 0x0F);
    I2CWriteByte(DEV_ADDR, 0x38, 0x18);
    I2CWriteByte(DEV_ADDR, 0x38, 0x08);
    msleep(100);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void N3_NoVideoCheck( n3_fmt_detect_param *pFmtDetectParam )
{
    int reg_b8;

    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
    reg_b8 = I2CReadByte(DEV_ADDR, 0xB8);

    printk("[N3_NoVideoCheck]%x\n", reg_b8);

    pFmtDetectParam->b0_b8 = reg_b8;
}

void N3_DetectFmt( n3_fmt_detect_param *pFmtDetectParam, int ch )
{
    int video_format;

    int reg_d0, reg_d1, reg_d2, reg_d3;
    int reg_f0;

    DEV_ADDR = pFmtDetectParam->devaddr;

    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
    I2CWriteByte(DEV_ADDR, 0x23+4*(ch%4), 0x41);
    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
    I2CWriteByte(DEV_ADDR, 0xB8, 0xB9);

    msleep(100);

    video_format = I2CReadByte(DEV_ADDR, 0xD0+ch%4);

    if(video_format != 0x00)
    {
        I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
        I2CWriteByte(DEV_ADDR, 0xB8, 0x38);
    }

    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
    reg_d0 = I2CReadByte(DEV_ADDR, 0xD0);
    reg_d1 = I2CReadByte(DEV_ADDR, 0xD1);
    reg_d2 = I2CReadByte(DEV_ADDR, 0xD2);
    reg_d3 = I2CReadByte(DEV_ADDR, 0xD3);

    printk("[N3_DetectFmt]%x %x %x %x\n", reg_d0, reg_d1, reg_d2, reg_d3);

    pFmtDetectParam->b0_d0 = reg_d0;
    pFmtDetectParam->b0_d1 = reg_d1;
    pFmtDetectParam->b0_d2 = reg_d2;
    pFmtDetectParam->b0_d3 = reg_d3;

    I2CWriteByte(DEV_ADDR, 0xFF, 0x05 + pFmtDetectParam->ch);
    reg_f0 = I2CReadByte(DEV_ADDR, 0xF0);

    pFmtDetectParam->b5to8_f0 = reg_f0;
}

void N3_NovideoRead( n3_novideo_param *pNoVideoParam )
{
    //unsigned char val_5xf0;
    DEV_ADDR = pNoVideoParam->devaddr;
    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
    pNoVideoParam->b1_d8 = I2CReadByte(DEV_ADDR, 0xB8);
    //I2CWriteByte(DEV_ADDR, 0xFF, 0x05);  //05.21
    //val_5xf0 = I2CReadByte(DEV_ADDR, 0xf0);
    //if(val_5xf0 == 0x30 || val_5xf0==0x31)
    //{
    //     pNoVideoParam->b1_d8 &= 0xFE;
    //     printk("video loss det but video fmt found 05.21!!!!\n\n\n");
    //}
}

void N3_SetInputChannel(  n3_init_param *pInitParam, int ch )
{
    int tmp;

    DEV_ADDR = pInitParam->devaddr;

    //I2CWriteByte(DEV_ADDR, 0xFF, 0);
    //I2CWriteByte(DEV_ADDR, 0x02, 0xFF&(~(1<<ch)));  //power on ch,and power down other ch2/3/4

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
    Write_I2C( DEV_ADDR, 0xC2, NULL, ch,1);

    Write_I2C( DEV_ADDR, 0xC0, NULL, ch,1);
    Write_I2C( DEV_ADDR, 0xC4, NULL, ch,1);
    Write_I2C( DEV_ADDR, 0xC6, NULL, ch,1);

    tmp = pInitParam->fmt_res;
    switch(tmp)
    {
        case VDEC_N3_FMT_SH720:
        case VDEC_N3_FMT_SH720_27MHz:
        case VDEC_N3_FMT_SH720_36MHz:
            I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
            I2CWriteByte(DEV_ADDR, 0xCD, 0x00);
            I2CWriteByte(DEV_ADDR, 0xCF, 0x00);

            I2CWriteByte(DEV_ADDR, 0xCC, 0x00);
            I2CWriteByte(DEV_ADDR, 0xCE, 0x00);

            printk("N3 720h channel select %d \n",ch);
            break;

        case VDEC_N3_FMT_720P:
            I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
            I2CWriteByte(DEV_ADDR, 0xCD, 0x43);
            I2CWriteByte(DEV_ADDR, 0xCF, 0x43);

            I2CWriteByte(DEV_ADDR, 0xCC, 0x43);
            I2CWriteByte(DEV_ADDR, 0xCE, 0x43);

            printk("N3 720p channel select %d \n",ch);

            break;
        case VDEC_N3_FMT_1080P:
            I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
            I2CWriteByte(DEV_ADDR, 0xCD, 0x69);
            I2CWriteByte(DEV_ADDR, 0xCF, 0x69);

            I2CWriteByte(DEV_ADDR, 0xCC, 0x69);
            I2CWriteByte(DEV_ADDR, 0xCE, 0x69);

            printk("N3 1080p channel select %d \n",ch);

            break;

    }
}

void N3_VideoFormat_Detection(  n3_init_param *pInitParam, int ch )
{
    int video_format;

    DEV_ADDR = pInitParam->devaddr;

    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
    I2CWriteByte(DEV_ADDR, 0x23+4*(ch%4), 0x41);
    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
    I2CWriteByte(DEV_ADDR, 0xB8, 0xB9);

    msleep(100);

    video_format = I2CReadByte(DEV_ADDR, 0xD0+ch%4);

    if(video_format != 0x00)
    {
        I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
        I2CWriteByte(DEV_ADDR, 0xB8, 0x38);
    }
}

void common_init(int _0ntsc1pal)
{
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK0,1);
//  Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B0_720p_25fps_Buf : N3_B0_720p_30fps_Buf,0, 255 );
    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B0_720p_25fps_Buf : N3_B0_720p_30fps_Buf,0, 175 );

    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK1,1);
//  Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B1_720p_25fps_Buf : N3_B1_720p_30fps_Buf,0, 255 );
    Write_I2C( DEV_ADDR, 0x80, _0ntsc1pal? N3_B1_720p_25fps_Buf : N3_B1_720p_30fps_Buf,0, 128 );

    /*
    --------------------[BANK = 2]----------------------
    0x00=0x13
    0x02=0x13
    0x04=0x13
    0x06=0x13
     */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK2,1);  //0x23:motion on ; 0x13: motion off
    Write_I2C( DEV_ADDR, 0x00, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x02, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x04, NULL, 0x13,1);
    Write_I2C( DEV_ADDR, 0x06, NULL, 0x13,1);

    /*
    --------------------[BANK = 3]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK3,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);

    /*
    --------------------[BANK = 4]----------------------
    0x6B=0x00
    0xEB=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK4,1);
    Write_I2C( DEV_ADDR, 0x6B, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0xEB, NULL, 0x00,1);


    /*
    --------------------[BANK = 9]----------------------
    0x40=0x00
    0x41=0x00
    0x42=0x00
    0x43=0x00
    0x44=0x00
    */
    Write_I2C( DEV_ADDR, 0xFF, NULL, BANK9,1);
    Write_I2C( DEV_ADDR, 0x40, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x41, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x42, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x43, NULL, 0x00,1);
    Write_I2C( DEV_ADDR, 0x44, NULL, 0x00,1);

}

void N3_Init_ch( int fmt_res ,int _0ntsc1pal,int ch)
{
    int tmp;

  // for(tmp=0;tmp<3;tmp++)
   {
        switch(fmt_res)
        {
            case VDEC_N3_FMT_SH720:
            case VDEC_N3_FMT_SH720_27MHz:
            case VDEC_N3_FMT_SH720_36MHz:
                    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
                    I2CWriteByte(DEV_ADDR, 0x08+ch%4, _0ntsc1pal?0xDD:0xA0);
                    I2CWriteByte(DEV_ADDR, 0x0c+ch%4, _0ntsc1pal?0x00:0xFF);
                    I2CWriteByte(DEV_ADDR, 0x10+ch%4, _0ntsc1pal?0x90:0x92);
                    I2CWriteByte(DEV_ADDR, 0x14+ch%4, _0ntsc1pal?0x80:0x80);
                    I2CWriteByte(DEV_ADDR, 0x18+ch%4, _0ntsc1pal?0x04:0x04);   //0x18 default ; 0x04
                    I2CWriteByte(DEV_ADDR, 0x21+4*(ch%4), _0ntsc1pal?0x02:0x82);
                    I2CWriteByte(DEV_ADDR, 0x22+4*(ch%4), _0ntsc1pal?0x0A:0x0A);
                    I2CWriteByte(DEV_ADDR, 0x23+4*(ch%4), _0ntsc1pal?0x41:0x41);
                    I2CWriteByte(DEV_ADDR, 0x30+ch%4, _0ntsc1pal?0x09:0x06);
                    I2CWriteByte(DEV_ADDR, 0x3c+ch%4, _0ntsc1pal?0x88:0x88);
                    I2CWriteByte(DEV_ADDR, 0x40+ch%4, _0ntsc1pal?0x00:0x01);
                    I2CWriteByte(DEV_ADDR, 0x44+ch%4, _0ntsc1pal?0x00:0x00);
                    I2CWriteByte(DEV_ADDR, 0x48+ch%4, _0ntsc1pal?0x00:0x00);
                    I2CWriteByte(DEV_ADDR, 0x4c+ch%4, _0ntsc1pal?0x04:0x00);
                    I2CWriteByte(DEV_ADDR, 0x50+ch%4, _0ntsc1pal?0x04:0x00);

                    //I2CWriteByte(DEV_ADDR, 0x54+ch%4, _0ntsc1pal?0x01:0xf1);
                    tmp = I2CReadByte(DEV_ADDR, 0x54);
                    if(_0ntsc1pal==1) //PAL
                    tmp &= ~(0x10<<(ch%4));
                    else
                    tmp |= (0x10<<(ch%4));
                    I2CWriteByte(DEV_ADDR, 0x54, tmp);

                    I2CWriteByte(DEV_ADDR, 0x58+ch%4, _0ntsc1pal?0x66:0x64); // h_delay adjust
                    I2CWriteByte(DEV_ADDR, 0x5c+ch%4, _0ntsc1pal?0x1E:0x1E);
                    I2CWriteByte(DEV_ADDR, 0x64+ch%4, _0ntsc1pal?0x0d:0x08);

                    if(fmt_res == VDEC_N3_FMT_SH720_36MHz || fmt_res != VDEC_N3_FMT_SH720_27MHz)
                    {
                        I2CWriteByte(DEV_ADDR, 0x81+ch%4, _0ntsc1pal?0x00:0x00);
                        I2CWriteByte(DEV_ADDR, 0x85+ch%4, _0ntsc1pal?0x11:0x11);
                    }
                    else if(fmt_res == VDEC_N3_FMT_SH720_27MHz)
                    {
                        I2CWriteByte(DEV_ADDR, 0x81+ch%4, _0ntsc1pal?0x10:0x00);
                        I2CWriteByte(DEV_ADDR, 0x85+ch%4, _0ntsc1pal?0x00:0x00);
                    }

                    I2CWriteByte(DEV_ADDR, 0x89+ch%4, _0ntsc1pal?0x11:0x11);
                    I2CWriteByte(DEV_ADDR, ch%4+0x8E, _0ntsc1pal?0x00:0x00);

                    I2CWriteByte(DEV_ADDR, 0x93+ch%4, _0ntsc1pal?0x00:0x00); //H zoom disable
                    I2CWriteByte(DEV_ADDR, 0x98+ch%4, _0ntsc1pal?0x09:0x09); // ZOOM Dot
                    I2CWriteByte(DEV_ADDR, 0xa0+ch%4, _0ntsc1pal?0x15:0x15);
                    I2CWriteByte(DEV_ADDR, 0xa4+ch%4, _0ntsc1pal?0x05:0x07);

                    #if 1 // 20170412 change cvbs picature size
                    I2CWriteByte(DEV_ADDR, 0x58+ch%4, _0ntsc1pal?0x84:0x87); // h_delay adjust
                    //I2CWriteByte(DEV_ADDR, 0x89+ch%4, _0ntsc1pal?0x01:0x01); //mask disable
                    I2CWriteByte(DEV_ADDR, 0x93+ch%4, _0ntsc1pal?0x01:0x01); //H zoom enable
                    I2CWriteByte(DEV_ADDR, 0x98+ch%4, _0ntsc1pal?0x09:0x09); // ZOOM Dot
                    #endif

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
                    I2CWriteByte(DEV_ADDR, 0x88+ch%4, 0x06);
                    I2CWriteByte(DEV_ADDR, 0x8c+ch%4, 0x06);
                    I2CWriteByte(DEV_ADDR, 0xa0+ch%4, 0x00);
                    I2CWriteByte(DEV_ADDR, 0xd7,I2CReadByte(DEV_ADDR, 0xd7)&(~(1<<(ch%4))));

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x02);
                    tmp = I2CReadByte(DEV_ADDR, 0x16+(ch%4)/2);
                    I2CWriteByte(DEV_ADDR,0x16+(ch%4)/2, (tmp&(ch%2==0?0xF0:0x0F))|(0x00<<((ch%2)*4)));

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
                    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720H_PAL_Buf : N3_B5678_720H_NTSC_Buf,0, 255 );

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x09);
                    I2CWriteByte(DEV_ADDR, 0x40+(ch%4), 0x60);
                    I2CWriteByte(DEV_ADDR, 0x44, I2CReadByte(DEV_ADDR, 0x44)&(~(1<<(ch%4))));
                    I2CWriteByte(DEV_ADDR, 0x46, 0x06);

                    printk("N3 720h each ch%d %s setting \n",ch,_0ntsc1pal?"PAL":"NTSC");
                    break;

            case VDEC_N3_FMT_720P:
            default:
                    I2CWriteByte(DEV_ADDR, 0xFF, 0x00);
                    I2CWriteByte(DEV_ADDR, 0x08+ch%4, _0ntsc1pal?0x60:0x60);
                    I2CWriteByte(DEV_ADDR, 0x0c+ch%4, _0ntsc1pal?0x08:0x08);
                    I2CWriteByte(DEV_ADDR, 0x10+ch%4, _0ntsc1pal?0x88:0x88);
                    I2CWriteByte(DEV_ADDR, 0x14+ch%4, _0ntsc1pal?0x90:0x90);
                    I2CWriteByte(DEV_ADDR, 0x18+ch%4, _0ntsc1pal?0x00:0x00);  //0x30 default
                    I2CWriteByte(DEV_ADDR, 0x21+4*(ch%4), _0ntsc1pal?0x92:0x92);
                    I2CWriteByte(DEV_ADDR, 0x22+4*(ch%4), _0ntsc1pal?0x0a:0x0a);
                    I2CWriteByte(DEV_ADDR, 0x23+4*(ch%4), _0ntsc1pal?0x41:0x41);
                    I2CWriteByte(DEV_ADDR, 0x30+ch%4, _0ntsc1pal?0x12:0x12);
                    I2CWriteByte(DEV_ADDR, 0x3c+ch%4, _0ntsc1pal?0x90:0x90);
                    I2CWriteByte(DEV_ADDR, 0x40+ch%4, _0ntsc1pal?0x00:0xfd);
                    I2CWriteByte(DEV_ADDR, 0x44+ch%4, _0ntsc1pal?0x30:0x30);
                    I2CWriteByte(DEV_ADDR, 0x48+ch%4, _0ntsc1pal?0x30:0x30);
                    I2CWriteByte(DEV_ADDR, 0x4c+ch%4, _0ntsc1pal?0x04:0x04);
                    I2CWriteByte(DEV_ADDR, 0x50+ch%4, _0ntsc1pal?0x04:0x04);

                    //I2CWriteByte(DEV_ADDR, 0x54+ch%4, _0ntsc1pal?0x01:0xf1);
                    tmp = I2CReadByte(DEV_ADDR, 0x54);
                    if(_0ntsc1pal==1) //PAL
                    tmp &= ~(0x10<<(ch%4));
                    else
                    tmp |= (0x10<<(ch%4));
                    I2CWriteByte(DEV_ADDR, 0x54, tmp);

                    I2CWriteByte(DEV_ADDR, 0x58+ch%4, _0ntsc1pal?0x80:0x90);
                    I2CWriteByte(DEV_ADDR, 0x5c+ch%4, _0ntsc1pal?0x9e:0x9e);
                    I2CWriteByte(DEV_ADDR, 0x64+ch%4, _0ntsc1pal?0xb1:0xb2);

                    I2CWriteByte(DEV_ADDR, 0x81+ch%4, _0ntsc1pal?0x07:0x06);
                    I2CWriteByte(DEV_ADDR, 0x85+ch%4, _0ntsc1pal?0x00:0x00);
                    I2CWriteByte(DEV_ADDR, 0x89+ch%4, _0ntsc1pal?0x10:0x10);
                    I2CWriteByte(DEV_ADDR, ch%4+0x8E, _0ntsc1pal?0x0d:0x0d);

                    I2CWriteByte(DEV_ADDR, 0x93+ch%4, _0ntsc1pal?0x00:0x00);
                    I2CWriteByte(DEV_ADDR, 0x98+ch%4, _0ntsc1pal?0x07:0x04);
                    I2CWriteByte(DEV_ADDR, 0xa0+ch%4, _0ntsc1pal?0x00:0x00);
                    I2CWriteByte(DEV_ADDR, 0xa4+ch%4, _0ntsc1pal?0x00:0x01);

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x01);
                    I2CWriteByte(DEV_ADDR, 0x88+ch%4, 0x00);
                    I2CWriteByte(DEV_ADDR, 0x8c+ch%4, 0x40);
                    I2CWriteByte(DEV_ADDR, 0xa0+ch%4, 0x01);
                    I2CWriteByte(DEV_ADDR, 0xd7,I2CReadByte(DEV_ADDR, 0xd7)|(1<<(ch%4)));

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x02);
                    tmp = I2CReadByte(DEV_ADDR, 0x16+(ch%4)/2);
                    I2CWriteByte(DEV_ADDR,0x16+(ch%4)/2, (tmp&(ch%2==0?0xF0:0x0F))|(0x05<<((ch%2)*4)));

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x05+ch%4);
                    Write_I2C( DEV_ADDR, 0x00, _0ntsc1pal? N3_B5678_720p_25fps_Buf : N3_B5678_720p_30fps_Buf,0, 255 );

                    I2CWriteByte(DEV_ADDR, 0xFF, 0x09);
                    I2CWriteByte(DEV_ADDR, 0x40+(ch%4), 0x00);
                    I2CWriteByte(DEV_ADDR, 0x44, I2CReadByte(DEV_ADDR, 0x44)&(~(1<<(ch%4))));
                    I2CWriteByte(DEV_ADDR, 0x46, 0x06);

                    printk("N3 720p each ch%d %s setting \n",ch,_0ntsc1pal?"PAL":"NTSC");
                break;
        }
    }
}

//#define _CHECK_INPUT_SIGNAL_
int N3_Init( n3_init_param *pInitParam, int arg_int)
{
    #ifdef _CHECK_INPUT_SIGNAL_
    int i;
    unsigned char b5xf0,b5xf3,b5xf5,b0x02;
    #endif
    DEV_ADDR = pInitParam->devaddr;

    if(pInitParam->fmt_res == VDEC_N3_FMT_SH720_27MHz || pInitParam->fmt_res == VDEC_N3_FMT_SH720_36MHz)
    {

        int _0ntsc1pal;
        _0ntsc1pal = pInitParam->fmt_fps == VDEC_N3_FMT_NTSC ? 0 : 1 ;

        WriteBankAll_N3_H720( _0ntsc1pal );

        N3_Init_ch(pInitParam->fmt_res, _0ntsc1pal, arg_int);   //CH1/2/3/4 720H

        //when no video, test pattern color setting
        I2CWriteByte(DEV_ADDR, 0xFF, 0);
        I2CWriteByte(DEV_ADDR, 0x78, 0x43);
        I2CWriteByte(DEV_ADDR, 0x79, 0x65);

        switch(pInitParam->fmt_res)
        {
            case VDEC_N3_FMT_SH720_27MHz :
                system_init_N3_H720(PLL_MODE_108MHz);
                printk("N3 720h 27MHz setting \n ");
            break;
            case VDEC_N3_FMT_SH720_36MHz :
                system_init_N3_H720(PLL_MODE_144MHz);
                printk("N3 720h 36MHz setting \n ");
            break;
            default :
                system_init_N3_H720(PLL_MODE_144MHz);
                printk("N3 720h 36MHz default setting \n ");
            break;
        }


    }
    else if(pInitParam->fmt_res == VDEC_N3_FMT_H960)
    {
        int _0ntsc1pal;
        _0ntsc1pal = pInitParam->fmt_fps == VDEC_N3_FMT_NTSC ? 0 : 1 ;
        WriteBankAll_N3_H960( _0ntsc1pal );
        system_init_N3_H960();
        printk("N3 960h setting \n ");
    }
    else if(pInitParam->fmt_res == VDEC_N3_FMT_720P)
    {
        int _0_30P_1_25P;
        _0_30P_1_25P = pInitParam->fmt_fps == VDEC_N3_FMT_30P ? 0 : 1 ;

        WriteBankAll_N3_720P( _0_30P_1_25P );

        //when no video, test pattern color setting
        I2CWriteByte(DEV_ADDR, 0xFF, 0);
        I2CWriteByte(DEV_ADDR, 0x78, 0x43);
        I2CWriteByte(DEV_ADDR, 0x79, 0x65);

        system_init_N3_720P();
        #ifdef _CHECK_INPUT_SIGNAL_
        msleep(300);
        for(i=0;i<2;i++)
        {
            I2CWriteByte(DEV_ADDR, 0xFF, 5);
            b5xf0 = I2CReadByte(DEV_ADDR, 0xf0);
            b5xf3 = I2CReadByte(DEV_ADDR, 0xf3);
            b5xf5 = I2CReadByte(DEV_ADDR, 0xf5);
            printk("5xF0 ==> %x\n", b5xf0);
            printk("5xF3 ==> %x\n", b5xf3);
            printk("5xF5 ==> %x\n", b5xf5);
            msleep(30);
            if(b5xf0==0xFF && (b5xf3!=0 || b5xf5!=0))
            {
                I2CWriteByte(DEV_ADDR, 0xFF, 0);
                b0x02 = I2CReadByte(DEV_ADDR, 0x02);
                I2CWriteByte(DEV_ADDR, 0x02, b0x02|0x01);
                msleep(30);
                I2CWriteByte(DEV_ADDR, 0x02, b0x02&0xFE);
            }
        }
        #endif
        printk("N3 720p setting \n");
    }
    else if(pInitParam->fmt_res == VDEC_N3_FMT_1080P)
    {
        int _0_30P_1_25P;
        _0_30P_1_25P = pInitParam->fmt_fps == VDEC_N3_FMT_30P ? 0 : 1 ;
        WriteBankAll_N3_1080P( _0_30P_1_25P );
        system_init_N3_1080P();

        //when no video, test pattern color setting
        I2CWriteByte(DEV_ADDR, 0xFF, 0);
        I2CWriteByte(DEV_ADDR, 0x78, 0x43);
        I2CWriteByte(DEV_ADDR, 0x79, 0x65);
        //I2CWriteByte(DEV_ADDR, 0xFF, 0);
        //I2CWriteByte(DEV_ADDR, 0x02, 0xFE);  //afe power down ch2/3/4
        I2CWriteByte(DEV_ADDR, 0xFF, 1);
        I2CWriteByte(DEV_ADDR, 0x00, 0x82);  //audio power down
        I2CWriteByte(DEV_ADDR, 0x97, 0x01);  //channel power down
        I2CWriteByte(DEV_ADDR, 0x98, 0x0E);  //channel power down2
        I2CWriteByte(DEV_ADDR, 0xCA, 0x22);  //bt656 port0 enable
        I2CWriteByte(DEV_ADDR, 0xFF, 0x05);
        I2CWriteByte(DEV_ADDR, 0x07, 0x20);
        video_fsc_check(0);
	//N3_video_chnl_stop(0);
	//msleep(30);
	//N3_video_chnl_start(0);
        #ifdef _CHECK_INPUT_SIGNAL_
        msleep(300);
        for(i=0;i<2;i++)
        {
            I2CWriteByte(DEV_ADDR, 0xFF, 5);
            b5xf0 = I2CReadByte(DEV_ADDR, 0xf0);
            b5xf3 = I2CReadByte(DEV_ADDR, 0xf3);
            b5xf5 = I2CReadByte(DEV_ADDR, 0xf5);
            printk("5xF0 ==> %x\n", b5xf0);
            printk("5xF3 ==> %x\n", b5xf3);
            printk("5xF5 ==> %x\n", b5xf5);
            msleep(30);
            if(b5xf0==0xFF && (b5xf3!=0 || b5xf5!=0))
            {
                I2CWriteByte(DEV_ADDR, 0xFF, 0);
                b0x02 = I2CReadByte(DEV_ADDR, 0x02);
                I2CWriteByte(DEV_ADDR, 0x02, b0x02|0x01);
                msleep(30);
                I2CWriteByte(DEV_ADDR, 0x02, b0x02&0xFE);
            }
        }
        #endif
        printk("N3 1080p[%s] setting \n", _0_30P_1_25P==0?"NTSC":"PAL");
    }
    else
    {
        printk("N3_drv : N3 : Not Suppoted format ??? \n");
    }

    return 0;
}

void N3_video_chnl_stop(unsigned char ch)
{
    unsigned char val_0x02, val_1x97, val_1x98;
    I2CWriteByte(DEV_ADDR, 0xFF, 0);
    val_0x02 = I2CReadByte(DEV_ADDR, 0x02);
    val_0x02 |= (0x01<<ch);
    I2CWriteByte(DEV_ADDR, 0x02, val_0x02);

    I2CWriteByte(DEV_ADDR, 0xFF, 1);
    val_1x97 = I2CReadByte(DEV_ADDR, 0x97);
    val_1x97 &= ~(1<<ch);
    I2CWriteByte(DEV_ADDR, 0x97, val_1x97);
    val_1x98 = I2CReadByte(DEV_ADDR, 0x98);
    val_1x98 |= (1<<ch);
    I2CWriteByte(DEV_ADDR, 0x98, val_1x98);
    printk("N3_drv : N3_video_chnl_stop[ch:%d] \n", ch);
}

void N3_video_chnl_start(unsigned char ch)
{
    unsigned char val_0x02, val_1x97, val_1x98;
    I2CWriteByte(DEV_ADDR, 0xFF, 0);
    val_0x02 = I2CReadByte(DEV_ADDR, 0x02);
    val_0x02 &= ~(0x01<<ch);
    I2CWriteByte(DEV_ADDR, 0x02, val_0x02);

    I2CWriteByte(DEV_ADDR, 0xFF, 1);
    val_1x97 = I2CReadByte(DEV_ADDR, 0x97);
    val_1x97 |= (1<<ch);
    I2CWriteByte(DEV_ADDR, 0x97, val_1x97);
    val_1x98 = I2CReadByte(DEV_ADDR, 0x98);
    val_1x98 &= ~(1<<ch);
    I2CWriteByte(DEV_ADDR, 0x98, val_1x98);
    printk("N3_drv : N3_video_chnl_start[ch:%d] \n", ch);
}


